<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>MapVGL</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #map_container {
      width: 100%;
      height: 100%;
      margin: 0;
    }
  </style>
  <script src="//api.map.baidu.com/api?v=1.0&type=webgl&ak=baiduKey"></script>
  <script src="//mapv.baidu.com/build/mapv.min.js"></script>
  <script src="../../js/common.js"></script>
  <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.119/dist/mapvgl.min.js"></script>
  <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.119/dist/mapvgl.threelayers.min.js"></script>
</head>
<body>
<div id="map_container"></div>
<script>
  // 6322,2363

  /* global BMapGL */

  /* global mapv */

  /* global mapvgl */

  /* global initMap */

  /* global purpleStyle */

  var map = initMap({
    tilt: 45,
    heading: 0,
    center: [111.858773,27.848930],
    zoom: 8.5,
    style: purpleStyle
  });

  var citys = [
    '长沙市',
    '株洲市',
    '湘潭市',
    '衡阳市',
    '邵阳市',
    '岳阳市',
    '常德市',
    '张家界市',
    '益阳市',
    '郴州市',
    '永州市',
    '怀化市',
    '娄底市'
  ];

  var randomCount = 100; // 模拟的飞线的数量
  var curve = new mapvgl.BezierCurve();

  var data = [];

  // 构造数据
  while (randomCount--) {
    var startPoint = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length, 10)]);
    var endPoint = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length, 10)]);

    curve.setOptions({
      start: [startPoint.lng, startPoint.lat],
      end: [endPoint.lng, endPoint.lat]
    });
    var curveModelData = curve.getPoints();

    data.push({
      geometry: {
        type: 'LineString',
        coordinates: curveModelData
      },
      properties: {
        count: Math.random()
      }
    });
  }

  var view = new mapvgl.View({
    map: map
  });

  var flylineLayer = new mapvgl.FlyLineLayer({
    style: 'chaos',
    step: 0.3,
    color: 'rgba(33, 242, 214, 0.3)',
    textureColor: function (data) {
      return data.properties.count > 0.5 ? '#ff0000' : '#56ccdd';
    },
    textureWidth: 20,
    textureLength: 10
  });
  view.addLayer(flylineLayer);
  flylineLayer.setData(data);
</script>
</body>
</html>
